package jjn.round1;

import commons.ListNode;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @author Jiang Jining
 * @since 2023-01-28 9:20
 */
public class Offer_6_ReversePrint {
    public int[] reversePrint(ListNode head) {
        Deque<Integer> queue = new LinkedList<>();
        while (head != null) {
            queue.offer(head.val);
            head = head.next;
        }
        int size = queue.size();
        int[] result = new int[size];
        int i = 0;
        while (!queue.isEmpty()) {
            result[i] = queue.pollLast();
            i++;
        }
        return result;
    }
}
